package com.cq.mqproer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    //队列 起名：TestQueue
    @Bean
    public Queue TestQueue() {
        return new Queue("TestQueue", true);
    }

    //Direct交换机 起名：TestExchange
    @Bean
    DirectExchange TestExchange() {
        return new DirectExchange("TestExchange", true, false);
    }

    //绑定  将队列和交换机绑定, 并设置匹配键：TestDirectRouting
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(TestQueue()).to(TestExchange()).with("TestDirectRouting");
    }

    @Bean
    DirectExchange lonelyDirectExchange() {
        return new DirectExchange("lonelyDirectExchange");
    }

}
